import { request } from 'umi';
import { OtherCost } from '@/data-type';
import { BaseService } from './baseService';
export class OtherCostServiceImpl implements BaseService<OtherCost>{
  async queryList(options?: { [key: string]: any; } | undefined): Promise<{ data: OtherCost[]; }> {
    console.log("queryList:", options);
    // let retData = {
    //   data: [
    //     {
    //       id: 1234568,
    //       programId: 123456,
    //       programDetailId: 123456,
    //       costType: "string",
    //       unitPrice: 1000,
    //       count: 1,
    //       paid: 500,
    //       unpaid: 500,
    //       amount: 1000,
    //       status: "正常",
    //       remarkId: "remarkId12345",
    //       startDate: new Date('2021-10-12'),
    //       endDate: new Date('2022-7-1'),
    //     },
    //     {
    //       id: 1234567,
    //       programId: 123456,
    //       programDetailId: 123456,
    //       costType: "string",
    //       unitPrice: 1000,
    //       count: 1,
    //       paid: 500,
    //       unpaid: 500,
    //       amount: 1000,
    //       status: "正常",
    //       remarkId: "remarkId12345",
    //       startDate: new Date('2021-10-12'),
    //       endDate: new Date('2022-7-1'),
    //     }
    //   ],
    // }
    // if (options?.id) {
    //   retData = { data: retData.data.filter((data, i, retData) => data.id == options.id) }
    // }
    let ret: OtherCost[] = [];
    await request("/other-cost/query_list", {
      method: "POST",
      data: {
        "id": options?.id,
      }
    }).then(response => {
      console.log("respose:", response);
      ret = response.data
    })
    return Promise.resolve({ data: ret });
  }
  async deleteOne(id: number): Promise<boolean> {
    console.log("need delete id is", id);
    await request("/other-cost/delete_one", {
      method: "DELETE",
      data: { id: id }
    })
    return Promise.resolve(true);
  }
  async updateOne(entity: OtherCost): Promise<boolean> {
    console.log("need update id is", entity);
    await request("/other-cost/update_one", {
      method: "PUT",
      data: { ...entity }
    })
    return Promise.resolve(true);
  }
  async save(entity: OtherCost): Promise<boolean> {
    console.log("保存成功", entity);
    await request("/other-cost/save_one", {
      method: "POST",
      data: { ...entity }
    })
    return Promise.resolve(true);
  }
}
export const OtherCostService: BaseService<OtherCost> = new OtherCostServiceImpl();